import pandas as pd
import numpy as np

# 定义df1
df1 = pd.DataFrame({
    'alpha': ['A', 'B', 'B', 'C', 'D', 'E'],
    'feature1': [1, 1, 2, 3, 3, 1],
    'feature2': ['low', 'medium', 'medium', 'high', 'low', 'high']
})

# 定义df2
df2 = pd.DataFrame({
    'alpha': ['A', 'A', 'B', 'F'],
    'pazham': ['apple', 'orange', 'pine', 'pear'],
    'kilo': ['high', 'low', 'high', 'medium'],
    'price': np.array([5, 6, 5, 7])
})
# 打印df1和df2
print(df1)
print(df2)

# 基于共同列alpha的内连接
inner_merge = pd.merge(df1, df2, on='alpha', how='inner')
print("内连接:")
print(inner_merge)

# 基于共同列alpha的左连接
left_merge = pd.merge(df1, df2, on='alpha', how='left')
print("\n左连接:")
print(left_merge)

# 基于共同列alpha的全部连接（也称为外连接）
outer_merge = pd.merge(df1, df2, on='alpha', how='outer')
print("\n全部连接:")
print(outer_merge)

# 基于共同列alpha的右连接
right_merge = pd.merge(df1, df2, on='alpha', how='right')
print("\n右连接:")
print(right_merge)